// DriveNotes. Copyright (c) 2011, Andrei Senchuk. All rights reserved.
package net.taviscaron.drivenotes.server.model.dao.impl;

import java.util.List;
import net.taviscaron.drivenotes.server.model.dao.ChargingDAO;
import net.taviscaron.drivenotes.shared.model.entity.Car;
import net.taviscaron.drivenotes.shared.model.entity.Charging;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * Charging DAO impl
 * @author Andrei Senchuk
 */
public class ChargingDAOImpl extends HibernateDaoSupport implements ChargingDAO {

    public Charging findById(Long id) {
        return getHibernateTemplate().load(Charging.class, id);
    }

    public void save(Charging charging) {
        getHibernateTemplate().saveOrUpdate(charging);
    }

    public void remove(Charging obj) {
        getHibernateTemplate().delete(obj);
    }

    @SuppressWarnings("unchecked")
    public List<Charging> findChargingsByCar(Car car) {
        return getHibernateTemplate().find("from Charging charging where car = ? order by charging.date desc", car);
    }
}
